import { http } from "@/utils/http";

export type PaidBillItem = {
  id: number;
  cellName: string;
  payer: string;
  payerType: number;
  phone: string;
  email: string;
  chargestandardName: string;
  price: number;
  receivableAmount: number;
  overdueAmount: number | null;
  totalAmount: number;
  paymentype?: number; // 1 预存款缴费 2 其他缴费（若存在）
  notification?: number | null; // 返回里可能有，但页面不展示
  remark: string;
};

export type PaidBillListParams = {
  page: number;
  limit: number;
  name: string;
};

export type PaidBillListResult = {
  code: number;
  data: PaidBillItem[];
  message: string;
};

export type PaidTotalAmountResult = {
  code: number;
  data: number;
  message: string;
};

export type DeletePaidBillsBody = {
  ids: number[];
};

export type DeletePaidBillsResult = {
  code: number;
  message: string;
};

// 查询已缴费账单列表
export const getPaidBillList = (params: PaidBillListParams) => {
  return http.request<PaidBillListResult>("post", "/SpBill/statusList1", {
    data: {
      page: params.page,
      limit: params.limit,
      name: params.name,
      notification: 0 // 按接口要求提供字段，但无实际影响
    }
  });
};

// 查询缴费总金额
export const getPaidTotalAmount = () => {
  return http.request<PaidTotalAmountResult>("get", "/SpBill/paiedTotalAmount");
};

// 删除（支持批量）
export const deletePaidBills = (ids: number[]) => {
  return http.request<DeletePaidBillsResult>("delete", "/SpBill/delete", {
    data: { ids }
  });
};
